2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
9 namespace SuperPolarity
17 ParticleEngine particleEngine;
19 public MainShip(Game newGame) : base(newGame) {}
21 public override void Initialize(Texture2D texture, Vector2 position)
23 base.Initialize(texture, position);
26 SetPolarity(Polarity.Positive);
35 void InitParticleEngine()
37 List<Texture2D> texturesList = new List<Texture2D>();
38 texturesList.Add(game.Content.Load<Texture2D>("Graphics\\circle"));
39 texturesList.Add(game.Content.Load<Texture2D>("Graphics\\diamond"));
40 texturesList.Add(game.Content.Load<Texture2D>("Graphics\\star"));
42 particleEngine = new ParticleEngine(texturesList, Position);
47 InputController.Bind("moveX", HandleHorizontalMovement);
48 InputController.Bind("moveY", HandleVerticalMovement);
49 InputController.Bind("changePolarity", HandleChangePolarity);
52 protected void HandleChangePolarity(float value)
57 public void HandleHorizontalMovement(float value)
59 Acceleration.X = value * AccelerationRate;
61 if (value > 0.1 && Velocity.X < 0 || value < 0.1 && Velocity.X > 0)
66 if (value > 0.1 && Velocity.Y < 0 || value < 0.1 && Velocity.Y > 0)
72 public void HandleVerticalMovement(float value)
74 Acceleration.Y = value * AccelerationRate;
77 public override void SwitchPolarity()
79 base.SwitchPolarity();
80 SwitchParticleEngine(CurrentPolarity);
83 public override void SetPolarity(Polarity newPolarity)
85 base.SetPolarity(newPolarity);
86 SwitchParticleEngine(newPolarity);
89 protected void SwitchParticleEngine(Polarity polarity)
91 if (polarity == Polarity.Positive)
93 particleEngine.Color = Color.Red;
95 else if (polarity == Polarity.Negative)
97 particleEngine.Color = Color.Blue;
101 particleEngine.Color = Color.Gray;
105 public override void Update(GameTime gameTime)
107 base.Update(gameTime);
108 particleEngine.EmitterLocation = Position;
109 particleEngine.Update();
113 public override void Magnetize(Ship ship, float distance, float angle)
117 protected void ConstrainToEdges()
128 if (Position.X > game.GraphicsDevice.Viewport.Width)
130 Position.X = game.GraphicsDevice.Viewport.Width;
146 if (Position.Y > game.GraphicsDevice.Viewport.Height)
148 Position.Y = game.GraphicsDevice.Viewport.Height;
157 public override void Draw(SpriteBatch spriteBatch)
159 particleEngine.Draw(spriteBatch);
160 base.Draw(spriteBatch);